﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace AiQiuQuan.Sport.Core.WechatPayV3
{
    /// <summary>
    /// 微信支付v3扩展
    /// </summary>
    internal static class WechatPayV3Extensions
    {
        /// <summary>
        /// 添加微信支付V3服务
        /// </summary>
        /// <param name="services">IServiceCollection</param>
        /// <param name="wechatPayOptionConfiguration">WechatPayOption IConfiguration</param>
        /// <returns></returns>
        public static IServiceCollection AddWechatPayV3(this IServiceCollection services, IConfiguration wechatPayOptionConfiguration)
        {
            services.Configure<WechatPayOption>(wechatPayOptionConfiguration);
            //注入平台证书管理服务
            services.AddSingleton<IWechatPayV3CertificateManagerFactory, WechatPayV3CertificateManagerFactory>();
            //注入v3支付clientfactory、
            services.AddSingleton<IWechatPayV3HttpClientFactory, WechatPayV3HttpClientFactory>();
            //注入平台证书刷新后台服务
            services.AddHostedService<WechatPayV3CertificateRefreshBackgroundService>();
            return services;
        }
    }
}
